package mya_dc.client.gui;

import java.util.LinkedList;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * A class that saves MOST of the strings that the user will see
 * 
 * @author      Adam Levi
 * <br>			MYA
 */
public class TextMessages {
	private TextMessages() {} //static class
	
	public static final String statusString_FILE_TRANSFER_START 	= "Transfering files to Server...";
	public static final String statusString_FILE_TRANSFER_DONE 		= "Transfer files complete, verifiying project...";
	public static final String statusString_PROJECT_FERIFICATION_DONE = "Project verification done";
	public static final String statusString_TRANSFER_UNKNOWN_ERROR 	= "Unknown Error while transferring files";
	public static final String statusString_COMPILATION_START 		= "Compiling project on Slaves...";	
	public static final String statusString_COMPILATION_SUCCESS 	= "Compiled project successfully";
	public static final String statusString_COMPILATION_UNABLE_TO_COMPILE 		= "Error while compiling, server error";
	public static final String statusString_COMPILATION_NO_SLAVES 	= "Could not compile, no slaves available";
	public static final String statusString_COMPILATION_UNKNOWN_ERROR = "Error while compiling, unknown error";
	public static final String statusString_COMPILATION_RESULT_ERRORS = "Error while compiling, see error list";
	public static final String statusString_CANCELED				= "Operation Canceled";
	public static final String statusString_IDLE					= "Idle";
	public static final String statusString_CONNECTING				= "Connecting to server..";
	public static final String statusString_CONNECTED				= "Connected to server";
	public static final String statusString_CONNECTIION_ERROR		= "Failed to connect";
	public static final String statusString_LOGIN_FAILED_AUTHENTICATION_FAILED	= "Could not connect to server, authentication failed";
	public static final String statusString_LOGIN_FAILED_USERNAME_ALREADY_EXISTS= "Could not connect to server, username already exists";
	public static final String statusString_LOGIN_FAILED_NO_MORE_SERVERS= "Could not connect to server, no compilation servers available";	
	public static final String statusString_ERROR_MASTER_SERVER_CONNECTION_FAILED= "Could not connect to server, master server is unavailable";		
	public static final String statusString_LOGIN_FAILED_SERVER_DISCONNECTED = "Error, the project's compilation server is disconnected";
	public static final String statusString_LOGIN_EXISTING			= "Error, a similar user is already connected to the server";
	
	
	public enum EMessageBoxType
	{
		ERROR_NO_PROJECT,
		ERROR_IS_CONNECTING,
		ERROR_UNABLE_TO_CONNECT,
		ERROR_LOADING_EDITOR,
		ERROR_NO_SERVERS_AVAILABLE,
		ERROR_EXECUTABLE_NOT_EXISTS,
		ERROR_UNABLE_TO_LAUNCH_EXE,
		ERROR_UNABLE_TO_LOAD_PROJECT,
		ERROR_UNABLE_TO_SAVE_PROJECT,
		ERROR_ALREADY_IN_PROGRESS,
		
		//errors in NewProjectWizard
		ERROR_MISSING_USERNAME,
		ERROR_MISSING_PASSWORD,
		ERROR_MISSING_PROJECTNAME,
		ERROR_BAD_HOME_DIRECTORY,
		ERROR_BAD_OUTPUT_FILENAME,
		ERROR_MISSING_MASTER_HOSTNAME,
		ERROR_MISSING_PORT_NUMBER,
		
		//errors in PropertiesWindow
		ERROR_BAD_EDITOR_PATH,
		ERROR_NUMBER_OF_RETRIES_NOT_INTEGER,
		ERROR_NUMBER_OF_SEC_BETWEEN_RETRIES_NOT_INTEGER,
		
		
	}
	public static void showMessageBox(LinkedList<EMessageBoxType> types, JFrame frame)
	{
		String errors = "The following errors have accured:\n";
		for (EMessageBoxType type : types)
		{
			errors += errorToString(type);
			errors += "\n";
		}
		JOptionPane.showMessageDialog(frame, errors, "Error Message", 0);
	}
	
	public static void showMessageBox(EMessageBoxType type, JFrame frame)
	{
		JOptionPane.showMessageDialog(frame, "Error, " + errorToString(type), "Error Message", 0);
	}
	
	private static String errorToString(EMessageBoxType type)
	{
		switch(type)
		{
			case ERROR_NO_PROJECT: 				return "no project";
			case ERROR_IS_CONNECTING: 			return "trying to connect";
			case ERROR_UNABLE_TO_CONNECT: 		return "unable to connect";
			case ERROR_LOADING_EDITOR: 			return "unable to load editor";
			case ERROR_NO_SERVERS_AVAILABLE: 	return "no servers available";
			case ERROR_EXECUTABLE_NOT_EXISTS:	return "executable doesn't exist";
			case ERROR_UNABLE_TO_LAUNCH_EXE:	return "unable to launch executable";
			case ERROR_UNABLE_TO_LOAD_PROJECT:	return "unable to load project";
			case ERROR_UNABLE_TO_SAVE_PROJECT: 	return "unable to save project";
			case ERROR_ALREADY_IN_PROGRESS:		return "already in progress";
			case ERROR_MISSING_USERNAME:		return "missing username"; 
			case ERROR_BAD_HOME_DIRECTORY:		return "missing home directory";
			case ERROR_MISSING_MASTER_HOSTNAME: return "missing master hostname";
			case ERROR_BAD_OUTPUT_FILENAME: 	return "missing output filename";
			case ERROR_MISSING_PASSWORD:		return "missing password";
			case ERROR_MISSING_PORT_NUMBER:		return "missing port number";
			case ERROR_MISSING_PROJECTNAME:		return "missing project name";
			case ERROR_BAD_EDITOR_PATH:			return "bad editor path";
			case ERROR_NUMBER_OF_RETRIES_NOT_INTEGER: return "number of retries in not an integer";
			case ERROR_NUMBER_OF_SEC_BETWEEN_RETRIES_NOT_INTEGER: return "number of seconds between retries in not an integer";
			default: 							return "Error, Unknown error";
		}
	}

}
